<!-- 客户线索池 -->
<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="客户名称" prop="customerName">
                    <el-input class="w-[280px]" v-model="queryParams.customerName" />
                </el-form-item>
                <el-form-item label="手机" prop="phone">
                    <el-input class="w-[280px]" v-model="queryParams.phone" />
                </el-form-item>
                <el-form-item label="电话" prop="number">
                    <el-input class="w-[280px]" v-model="queryParams.number" />
                </el-form-item>
                <el-form-item label="线索类型" prop="type">
                    <el-select v-model="queryParams.type" class="w-[280px]" clearable>
                        <el-option label="全部" value="" />
                        <el-option label="未转客户的线索" value="1" />
                        <el-option label="已转客户的线索" value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="线索状态" prop="status">
                    <el-select v-model="queryParams.status" class="w-[280px]" clearable>
                        <el-option label="全部" value="" />
                        <el-option label="联系方式有效" value="1" />
                        <el-option label="未处理" value="2" />
                        <el-option label="联系方式无效" value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="前业务人员" prop="formerBusinessPersonnelId">
                    <el-select
                        v-model="queryParams.formerBusinessPersonnelId"
                        class="w-[280px]"
                        clearable
                    >
                        <el-option label="张三" value="1" />
                        <el-option label="李四" value="2" />
                        <el-option label="王五" value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="创建人" prop="userId">
                    <el-select v-model="queryParams.userId" class="w-[280px]" clearable>
                        <el-option label="张三" value="1" />
                        <el-option label="李四" value="2" />
                        <el-option label="王五" value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                    <daterange-picker
                        v-model:startTime="queryParams.createTimeStart"
                        v-model:endTime="queryParams.createTimeEnd"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <div class="centerBtn">
                <el-button v-perms="['cluepool:add']" type="primary">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    导出
                </el-button>
            </div>
            <el-table size="large" v-loading="pager.loading" :data="pager.lists" stripe>
                <el-table-column label="" prop="id" min-width="50" />
                <el-table-column label="联系人" sortable prop="contactName" min-width="130" />
                <el-table-column label="客户名称" sortable prop="customerName" min-width="130" />
                <el-table-column label="电话" sortable prop="number" min-width="150" />
                <el-table-column label="手机" sortable prop="phone" min-width="150" />
                <el-table-column label="线索类型" sortable prop="type" min-width="130" />
                <el-table-column label="线索状态" sortable prop="status" min-width="130" />
                <el-table-column
                    sortable
                    label="下次跟进时间"
                    prop="nextFollowUpTime"
                    min-width="150"
                />
                <el-table-column
                    sortable
                    label="前业务人员"
                    prop="formerBusinessPersonnelName"
                    min-width="130"
                />
                <el-table-column label="创建人" sortable prop="userName" min-width="130" />
                <el-table-column label="创建时间" sortable prop="createTime" min-width="130" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['cluepool:edit']"
                            type="primary"
                            link
                            @click="scratch = true"
                        >
                            抢
                        </el-button>
                        <!-- <el-button v-perms="['cluepool:del']" type="danger" link @click="handleDelete(row.id)">
                            删除
                        </el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <el-dialog title="系统信息" v-model="scratch">
            <span> 是否抢入该线索 </span>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="scratch = false">取消</el-button>
                    <el-button type="primary" @click="scratch = false"> 确定 </el-button>
                </div>
            </template>
        </el-dialog>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="cluepool">
import { cluepoolDelete, cluepoolLists } from '@/api/cluepool'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const scratch = ref(false)
const queryParams = reactive({
    customerName: '',
    number: '',
    phone: '',
    type: '',
    status: '',
    formerBusinessPersonnelId: '',
    userId: '',
    createTimeStart: '',
    createTimeEnd: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: cluepoolLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await cluepoolDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
